
#ifndef GraphicsWindowStatics_H
#define GraphicsWindowStatics_H

#include "GraphicsWindowPreprocessor.h"
#include "GraphicsWindowPrimer.h"

#include <string>

#if defined(GLUT_WIN)
#include "glut.h"

#elif defined(WIN_WIN)
#include <windows.h>
#endif

using namespace std;

class GraphicsWindowStatics {
	public:		
	
		GraphicsWindowStatics();
		~GraphicsWindowStatics();

		void initWindow(GraphicsWindowPrimer* pgwp);
		
#if defined(WIN_WIN)
		//functions only for Windows window
		bool winCreateWindow(string winName, int w, int h, int x, int y, bool pfullscreen);
		void winMainLoop();
		void winExitMainLoop();
		void winPostRedisplay();
		void winSwapBuffers();

		//static member for window proc callback
		static LRESULT CALLBACK stWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

		// returns a pointer the window (stored as the WindowLong)
		inline static GraphicsWindowStatics *GetObjectFromWindow(HWND hWnd) {
			return (GraphicsWindowStatics *)GetWindowLong(hWnd, GWL_USERDATA);
		}
#endif

	private:

		static void CallBackDisplayFunc(void);
		static void CallBackIdleFunc(void); 
		static void CallBackKeyboardFunc(unsigned char key, int x, int y);
		static void CallBackMotionFunc(int x, int y);
		static void CallBackMouseFunc(int button, int state, int x, int y);
		static void CallBackPassiveMotionFunc(int x, int y);
		static void CallBackReshapeFunc(int w, int h); 
		static void CallBackSpecialFunc(int key, int x, int y);

		void initFuncs();

		//Windows window members
#if defined(WIN_WIN)
		//window proc callback
		LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);	
		void winClearWindow();
		char getASCII(WPARAM key);

		HGLRC		hRC;		//rendering context
		HDC			hDC;		//device context
		HWND		hWnd;		//window handle
		HINSTANCE	hInstance;  //instance of app

		int Gheight, Gwidth;
		bool active;
		bool done;
		bool mouseDown;
		bool fullscreen;
		MSG msg;
#endif

};

extern GraphicsWindowPrimer* gwp;

#endif	  /*  GraphicsWindowStatics_H  */
